﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;

namespace Web.admin.NewsManage.Photos
{
    public partial class PhotoList : System.Web.UI.Page
    {
        BLL.PhotoService photoservice = new BLL.PhotoService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Rp_ListBind();
            }
        }

        /// <summary>
        /// repeater绑定
        /// </summary>
        protected void Rp_ListBind()
        {
            Rp_Photo.DataSource = photoservice.GetAllPhotos();
            Rp_Photo.DataBind();
        }

        /// <summary>
        /// repeater绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rp_DataBind(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                BoPhotos BoModel = (BoPhotos)e.Item.DataItem;
                LinkButton lbShow = (LinkButton)e.Item.FindControl("configShow");
                LinkButton lbNotShow = (LinkButton)e.Item.FindControl("CancelShow");
                if (BoModel.PHO_IsRound)
                {
                    lbShow.Visible = false;
                    lbNotShow.Visible = true;
                }
                else
                {
                    lbShow.Visible = true;
                    lbNotShow.Visible = false;
                }
            }
        }

        /// <summary>
        /// repeater事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rp_Event(object sender, RepeaterCommandEventArgs e)
        {
            string PhotoId = ((HiddenField)e.Item.FindControl("hf_Id")).Value;
            BoPhotos PhotoModel = photoservice.getPhoto(PhotoId);
            switch (e.CommandName)
            { 
                case "configShow":
                    if (photoservice.GetIsRound() >= 5)
                    {
                        Response.Write("<script>alert('轮显只能为五张图片，请先取消一些轮显，再设置此图片为轮显')</script>");
                        return;
                    }
                    else
                    {
                        PhotoModel.PHO_IsRound = true;
                    }
                        break;
                case "CancelShow":
                    PhotoModel.PHO_IsRound = false;
                    break;
            }
            photoservice.ModifyPhoto(PhotoModel);
            Rp_ListBind();
        }


    }
}